const db = require('../db/index')



// 展示上传图片页面
exports.getUploadPage = (req, res) => {
  res.render("nav")
}
// 获取产品图片
exports.getPic = (req, res) => {
  // 定义查询分类列表数据的 SQL 语句
  const sql = 'select * from product where type=? order by id asc'
  // 调用 db.query() 执行 SQL 语句
  db.query(sql, req.query.type, (err, results) => {
    if (err) return res.cc(err)
    res.send({
      status: 0,
      message: '获取产品图片成功!',
      data: results
    })
  })
}

exports.addProductPic = (req, res) => {
  console.log(req.body)
  const sql = 'insert into product set ?'
  // insert into product set ?
  // 调用 db.query() 执行 SQL 语句
  console.log(req.file)
  res.send({
    message: "success"
  })
  // db.query(sql, { picture: req.file.path, title: req.body.title, type: req.body.type }, (err, results) => {
  //   if (err) return res.send({ err: err })
  //   res.send({
  //     body: req.body,
  //     file: req.file,
  //     data: results
  //   })
  // })
}